//
//  SRTaskSettingView.m
//  SportRing
//
//  Created by mykoma on 14-4-7.
//  Copyright (c) 2014年 HotOne. All rights reserved.
//

#import "SRTaskSettingView.h"
#import "SRHelper.h"

@interface SRTaskSettingView() <UITextFieldDelegate>

@property (nonatomic, assign) UInt32 targetSteps;

@property (weak, nonatomic) IBOutlet UITextField *stepTF;

@property (weak, nonatomic) IBOutlet UILabel *distanceLabel;

@property (weak, nonatomic) IBOutlet UILabel *calorieLabel;

@end

@implementation SRTaskSettingView

-(void)awakeFromNib
{
    self.stepTF.textAlignment = NSTextAlignmentRight;
    self.distanceLabel.textAlignment = NSTextAlignmentRight;
    self.calorieLabel.textAlignment = NSTextAlignmentRight;
    [self.stepTF addTarget:self
                    action:@selector(stepValueChanged:)
          forControlEvents:UIControlEventEditingChanged];
}

#pragma mark - SRBaseViewProtocol

#pragma mark - Button Actions

-(void)stepValueChanged:(UITextField *)textField
{
    self.targetSteps = textField.text.intValue;
    
    if ([self.dataSource respondsToSelector:@selector(distanceMeterBySteps:)])
    {
        int meters = [self.dataSource distanceMeterBySteps:self.targetSteps];
        self.distanceLabel.text = [NSString stringWithFormat:@"%d 米", meters];
    }
    
    if ([self.dataSource respondsToSelector:@selector(caloriesBySteps:)])
    {
        int calories = [self.dataSource caloriesBySteps:self.targetSteps];
        self.calorieLabel.text = [NSString stringWithFormat:@"%d 千卡", calories];
    }
}

- (IBAction)touchOnSaveBtn:(id)sender
{
    if ([self.delegate respondsToSelector:@selector(saveTaskWithSteps:)])
    {
        [self.delegate saveTaskWithSteps:self.targetSteps];
    }
}

@end
